<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table2">
<div class="content-table-title"><?=$this->title?></div>
<div class="form-edit-task2">
<br>
<form action="/contracts/add-contract-step2" method="post" name="form1" onsubmit="submitform(this);return false;">
<div align="center">输入关键字搜索客户：&nbsp;&nbsp;<input type="text" placeholder="客户关键字" name="keyword" id="keyword" style="width: 300px" onkeyup="Search(this)"></div>
<br /><input type="hidden" name="client_id" id="client_id" value="" />
<div align="center" style="height:300px;width:700px;overflow:auto;border:1px solid red;margin-left: auto;margin-right: auto;">
<table border="0" width="100%" id="client_list"></table>
</div>
<br /><br />
<div align="center"><input type="hidden" name="contract_type_id" value="<?=$this->contract_type_id?>" /><input type="button" class="buttonlong" value="下一步" onclick="submitform();return false;" />
<br><br><br>
<font color="red" size="1">如果找不到客户，请<a href="/clients/index">【查询客户状态】</a>或<a href="/clients/add-client">【申请新客户】</a>，等待审核后再次尝试搜索</font></a>
</div>
</form>
</div>
<br/><br/>
</div>

<script>
function Search(keyword)
{
	var kw = keyword.value;
	
	$.ajax({
			type: "post",
			url : "/ajax/get-client-list",
			dataType:'json',
            async:false,
			data: {
					"kw":kw
				  },
				success: function(json){
					if(json.result == 1 && typeof(json.data) != "undefined") {
                        var arr = json.data;
						var txt = "";
						
                        for(i=0; i < arr.length; i++){
							txt += "<tr><td width='200' align='right'><input type='radio' name='client_id' id='client_id_" + arr[i]['id'] + "' value='" + arr[i]['id'] + "'></td><td align='left'><label for='client_id_" + arr[i]['id'] + "'>&nbsp;&nbsp;&nbsp;&nbsp;" + arr[i]['name'] + "</label></td></tr>";
                        }
						
						document.getElementById("client_list").innerHTML = txt;
                    }
			}
		});
}

function submitform() 
{
	
	if( document.form1.client_id.value.length == 0 )
	{
		alert("请选择一个客户");
		return false;
	}
	
	form1.submit();
}
</script>
